#coding:utf-8
# -*- coding: utf-8 -*-
#@Time : 2020/12/4 21:03
#@Author: 王鹏-wangpeng99
#@File : Test.py

from datetime import datetime
import requests
from faker import Faker
import json
from utils import dtutils

zhfaker = Faker(locale='zh-CN')

jsonstr="""{
  "output": "output2.children",
  "outputs": {
    "id": "output2",
    "property": "children"
  },
  "inputs": [
    {
      "id": "wifiUploadBtn",
      "property": "n_clicks",
      "value": 1
    }
  ],
  "changedPropIds": [
    "wifiUploadBtn.n_clicks"
  ],
  "state": [
    {
      "id": "wifi-ts-input",
      "property": "value",
      "value": "2020-12-21 17:23:45"
    },
    {
      "id": "link-input",
      "property": "value",
      "value": "3"
    },
    {
      "id": "level-input",
      "property": "value",
      "value": "-2"
    },
    {
      "id": "noise-input",
      "property": "value",
      "value": "-5"
    }
  ]
}"""
jsondata = json.loads(jsonstr)
print(jsondata)

for _ in range(100):
    dt = zhfaker.past_datetime(start_date="-30d", tzinfo=None)
    dtstr = dt.strftime("%Y-%m-%d %H:%M:%S")
    link = zhfaker.random_digit()
    level = zhfaker.random_digit()*-1
    noise = zhfaker.random_digit()*-1
    for item in jsondata['state']:
        if item['id']=='wifi-ts-input':
            item['value'] = dtstr
        if item['id'] == 'link-input':
            item['value'] = str(link)
        if item['id'] == 'level-input':
            item['value'] = str(level)
        if item['id'] == 'noise-input':
            item['value'] = str(noise)
    print(jsondata)
    res = requests.post(url="http://49.233.119.96:8050/_dash-update-component", json=jsondata)
    # res = requests.post(url="http://localhost:8050/_dash-update-component", json=jsondata)
    print(res.text)

